<template>
  <el-dialog :append-to-body="true" :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog page" width="1200px" @open="open" @close="close">
    <el-form class="tl-form stakeholderForm" ref="form" :model="model" :rules="rules" label-width="300px">
			<el-row>
				<el-col :span="8">
					<el-form-item label="满分" prop="fullscore" :rules="rules.validateRequire">
						<el-input v-model="model.fullscore" type="number" :disabled="true" oninput="this.value=this.value.match(/\d{0,}\.?\d{0,1}/)"></el-input>
						<span class="unitSpan">分</span>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item label="自评分" prop="selfscore" :rules="rules.validateRequire">
						<el-input v-model="model.selfscore" type="number" :disabled="true" oninput="this.value=this.value.match(/\d{0,}\.?\d{0,1}/)"></el-input>
						<span class="unitSpan">分</span>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="目标得分" prop="targetscore" :rules="rules.validateRequire">
						<el-input v-model="model.targetscore" :disabled="true" type="number"></el-input>
						<span class="unitSpan">分</span>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="分差" prop="scoregap" :rules="rules.validateRequire">
						<el-input v-model="model.scoregap" :disabled="true"></el-input>
						<span class="unitSpan">分</span>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
			<el-col :span="8">
				<el-form-item label="新自评分" prop="selfscore" :rules="rules.validateRequire">
					<el-input v-model="selfscore" type="number" @change="changescore" oninput="this.value=this.value.match(/\d{0,}\.?\d{0,1}/)"></el-input>
					<span class="unitSpan">分</span>
				</el-form-item>
			</el-col>
			<el-col :span="8">
					<el-form-item label="新目标得分" prop="targetscore" :rules="rules.validateRequire">
						<el-input v-model="targetscore" @change="changescore" type="number" oninput="this.value=this.value.match(/\d{0,}\.?\d{0,1}/)"></el-input>
						<span class="unitSpan">分</span>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="分差" prop="scoregap" :rules="rules.validateRequire">
						<el-input v-model="scoregap" :disabled="true"></el-input>
						<span class="unitSpan">分</span>
					</el-form-item>
				</el-col>
			</el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit"><svg-icon icon-class="save" />保存</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
/** 子组件 */
import TlRefStakeholder from '../mpmProjectStakeholder/refList'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit],
  components: { TlRefStakeholder },
  data() {
    return {
      moduleTitle: '评分',
      urlPrefix: '/mpm/projectBidScore/',
      url: {
        // 额外的url
		queryMpmInfo: '/mpm/projectBidScore/queryMpmInfo/'
      },
      externalQueryParam: {
        qry_projectcode: this.projectinfo.projectcode // 项目编号
      },
      pickerOptions: {
        disabledDate: time => {
			if (this.projectinfo.bidscoreflag === 1) {
				return
			} else {
				return time.getTime() > this.biddate.getTime() || time.getTime() < new Date().getTime()
			}
        }
      },
      title: '变更评分',
      selfscore: '',
      targetscore: '',
      scoregap: '',
      visible: false
    }
  },
  props: {
    projectinfo: {},
    biddate: {
      type: Date,
      default: new Date()
    }
  },
  methods: {
	beforeSubmit() {
		if (!this.selfscore || !this.targetscore) {
			this.$tap.alert('请填写新评分！')
			return false
		}
		this.$set(this.model, 'selfscore', this.selfscore)
		this.$set(this.model, 'targetscore', this.targetscore)
		this.$set(this.model, 'scoregap', this.scoregap)
		return true
	},
	afterSubmit() {
		this.visible = false
	},
	changescore() {
		// 满分
		let fullscore = parseFloat(this.model.fullscore ? this.model.fullscore : 0)
		// 自评分
		let selfscore = parseFloat(this.model.selfscore ? this.model.selfscore : 0)
		// 目标得分
		let targetscore = parseFloat(this.model.targetscore ? this.model.targetscore : 0)
		if (fullscore > 100) {
			this.$tap.alert('满分不能大于100！')
			this.$set(this.model, 'fullscore', '100')
			this.$set(this.model, 'scoregap', (100 - selfscore + '').indexOf('.') > 0 ? Number(100 - selfscore).toFixed(1) + '' : Number(100 - selfscore) + '')
			return
		}
		if (fullscore < selfscore) {
			this.$tap.alert('自评分不能大于满分！')
			this.$set(this.model, 'selfscore', '0')
			this.$set(this.model, 'scoregap', fullscore + '')
			return
		}
		if (fullscore < targetscore) {
			this.$tap.alert('目标得分不能大于满分！')
			this.$set(this.model, 'targetscore', '0')
			return
		}
		if (selfscore > targetscore && this.model.targetscore) {
			this.$tap.alert('自评分不能大于目标得分！')
			this.$set(this.model, 'scoregap', fullscore + '')
			this.$set(this.model, 'selfscore', '0')
			return
		}
		if (fullscore > 0) {
			let a = (fullscore - selfscore + '').indexOf('.') > 0 ? Number(fullscore - selfscore).toFixed(1) : Number(fullscore - selfscore)
			this.$set(this.model, 'scoregap', (fullscore - selfscore + '').indexOf('.') > 0 ? Number(fullscore - selfscore).toFixed(1) + '' : Number(fullscore - selfscore) + '')
		}
	}
  }
}
</script>
<style scoped lang="scss">
.stakeholderForm {
  margin-top: 15px;
  margin-left: -220px;
  .el-row {
    margin-bottom: 2px;
  }
  /* 隐藏禁用状态下的提示 */
  .is-disabled ::placeholder {
    color: transparent !important;
  }
}
.tl-ref-user {
  /deep/ .tl-ref-selector {
    .el-button {
      background-color: red !important;
    }
  }
}
</style>
